/**
 *  *2010-5-23 下午10:53:00  add 
 */
package com.base.myproject.client.HR.Salary;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.Editdisable;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.print.Printer;
import com.base.myproject.client.busi.print.ReportPrintDialog;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.BaseResource;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseBusiLeftPanel;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Administrator 2010-5-23 javazgw@gmail.com
 */
public class Salary extends BaseJDBCPanel implements BaseStoreListener{
	BaseStore<BusiObject> store = null;
	BaseStore mstore = new BaseStore();
	BaseStore mstore2 = new BaseStore();
	BaseStore mstore3 = new BaseStore();
	BaseStore mstore4 = new BaseStore();
	BaseStore mstore5 = new BaseStore();
	BaseStore mstore6 = new BaseStore();
	BaseStore mstore7 = new BaseStore();
	
	Button seal = new Button("封存");
	Button seal_cancel = new Button("解封");
	Button ratify = new Button("审核通过");
	Button printer =  new Button("打印明细");
	Button export =  new Button("导出银行单");
	Button deleteAll =  new Button("删除发薪数据");
	Button delete =  new Button("删除当前记录");
	String icode;
	TabPanel tabpanel = new TabPanel();
	Button search = new Button("查询");
	
	//String bcode = "";  //修改个税的员工编号
	//String upcode = "";  //修改个税的薪金编码
	
	private BaseBusiLeftPanel<BusiObject> basbusileftpanel = null;
	
	public Salary() {
		init();
		registerMainStore(store);
		registerStore(store);
	}
	
	public Salary(String icode){
		this.icode = icode;
		init();
		registerMainStore(store);
		registerStore(store);
	}

	public void init() {
		init_store();//演示需要的临时数据
		this.add(initWeigetx());
		printer.setIcon(AbstractImagePrototype.create(BaseResource.INSTANCE.print_16()));
		
		seal.addListener(Events.Select, getListener());
		seal_cancel.addListener(Events.Select, getListener());
		search.addListener(Events.Select, getListener());
		printer.addListener(Events.Select, getListener());
		export.addListener(Events.Select, getListener());
		ratify.addListener(Events.Select, getListener());
		deleteAll.addListener(Events.Select, getListener());
		delete.addListener(Events.Select, getListener());
	}

	public void complete() {
		super.complete();
		//ratify.setText("提交确认");
		getToolbarll().add(new SeparatorToolItem());
		getToolbarll().add(seal);
		getToolbarll().add(seal_cancel);
		getToolbarll().add(new SeparatorToolItem());
		getToolbarll().add(printer);
		getToolbarll().add(export);
		getToolbarll().add(deleteAll);
		getToolbarll().add(new SeparatorToolItem());
		getToolbarll().add(delete);
	}
	protected void save()
	{
		final java.util.Vector<String> v = new java.util.Vector<String>();
		v.addAll(getSalaryStore()._trySave());
		final String upcode = getSalaryStore().getValue("upcode").toString();
		final String bcode = getSalaryStore().getValue("bcode").toString();
		
		if (v.size() > 0) {
			MessageBox.confirm("提示", "您已对薪金明细做了更改，是否保存？选择是则保存并重新计税，否则不保存！", 
					new Listener<MessageBoxEvent>() {
				public void handleEvent(MessageBoxEvent be) {
					if (be.getButtonClicked().getText().equals(
									GXT.MESSAGES.messageBox_yes())) {
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
										.create(com.base.myproject.client.tools.GreetingService.class);
								greetingService.saveBaseObject(v, null,
										new AsyncCallback<String>() {
											@Override
											public void onFailure(
													Throwable caught) {
												MessageBox.alert("错误",
														"网络连接失败", null);
											}

											@Override
											public void onSuccess(String result) {
												// TODO Auto-generated method
												// stub
												final List<String> list = new ArrayList<String>();
												String deleteSql = "delete hr_salary where upcode = '"
														+ upcode
														+ "' and bcode = '"
														+ bcode
														+ "' and allowanceno_ = 'A99'";
												list.add(deleteSql);

												String selectMoneySql = "select case when taxbase>freetax then -((taxbase-freetax)*tax-netnum) else 0 end as amount "
														+ "from (select sum(amount) as taxbase from hr_salary  where bcode = '"
														+ bcode
														+ "' and "
														+ "exists(select * from hr_Salary_Item where iftax = '1' and code = allowanceno_) and upcode='"
														+ upcode
														+ "') as taxbase "
														+ "left join "
														+ "(select *,(select taxfree from hr_tax where hr_tax.code=hr_taxdetail.upcode ) "
														+ "as freetax from hr_taxdetail "
														+ "where exists (select * from hr_tax,hr_salary_main_c where hr_salary_main_c.code='"
														+ upcode
														+ "' "
														+ "and hr_tax.code=hr_taxdetail.upcode and effectstartdate<=hr_salary_main_c.Start_time "
														+ "and  (effectenddate > hr_salary_main_c.End_time or  effectenddate is null) )) as hr_taxdetail "
														+ "on amountstart<=taxbase-freetax and taxbase-freetax<amountend";
												final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT
														.create(com.base.myproject.client.tools.GreetingService.class);
												greetingService2
														.getDataSet(
																selectMoneySql,
																new AsyncCallback<DataSet>() {
																	@Override
																	public void onFailure(
																			Throwable caught) {
																	}

																	@Override
																	public void onSuccess(
																			DataSet result) {
																		String money = result
																				.getValue(
																						0,
																						"amount");
																		if (!money
																				.startsWith("0")) {
																			String insertTaxSql = "insert hr_salary(amount,bcode,createdate,upcode,salarytype,allowanceno_,readOnly) values("
																					+ money
																					+ ", '"
																					+ bcode
																					+ "',getdate(), '"
																					+ upcode
																					+ "','4','A99','1')";
																			list
																					.add(insertTaxSql);
																		}
																		update(
																				list, "更新个税成功");
																	}
																});
											}
										});
					}
				}
			});
		}
	}

	private Widget initWeigetx() {
		VerticalPanel v = new VerticalPanel();
		HorizontalPanel h = new HorizontalPanel();
		HorizontalPanel hp = new HorizontalPanel();
		v.setHorizontalAlign(HorizontalAlignment.LEFT);
		h.setVerticalAlign(VerticalAlignment.TOP);
		h.add(CreateCcodeLeftPanel());
		v.add(createForm());
		v.setSpacing(1);
		hp.add(createSalaryGrid());
		hp.add(createGrid());
		v.add(hp);
		h.add(v);
		
		h.setSpacing(2);
		return h;
	}

	public ContentPanel CreateCcodeLeftPanel() {
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

		ColumnConfig name = new ColumnConfig("code", "发薪编码", 100);

		columns.add(name);

		ColumnModel cm = new ColumnModel(columns);

		// --set modetype
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_salary_main_c");
		info.setKeyname(new String[] { "icode" });
		info.setForcenolimit("true");
		info.setSql("select icode,code from hr_salary_main_c where "+(icode==null?" 1=1 ":"code='"+icode+"'")+" and  exists (select * from hr_salary where hr_salary.upcode = hr_salary_main_c.code having count(*)>0) order by code desc");
	
		basbusileftpanel = new BaseBusiLeftPanel<BusiObject>(
				columns, type, info,false,false);
		store = basbusileftpanel.getStore();
		basbusileftpanel.setWidth(170);
		basbusileftpanel.getGrid().setWidth("180");
		setMaincomponent(basbusileftpanel.getGrid());
		return basbusileftpanel.getPanel();
	}

	BaseFormPanel form = null;
	TextField<String> searchText;

	BaseFormPanel createForm() {
		BaseFormPanel form = new BaseFormPanel(new BaseStore<BusiObject>(),false);
		form.setWidth(810);
		TableLayout tl = new TableLayout(7);

		TableData td = new TableData();
		td.setRowspan(1);
		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);
		td.setPadding(2);
		form.setLayout(tl);
		form.setHeaderVisible(false);

	
		form.add(new Label("编号/姓名查询:"), td);
		searchText = new TextField<String>();
		form.add(searchText, td);
		
		form.add(search, td);
		
		form.inited();
		return form;
	};
	BaseStore<BusiObject> Salarystore = null;

	BaseStore<BusiObject> getSalaryStore() {
		if (Salarystore == null) {
			createSalaryStore();
		}
		return Salarystore;
	}

	BaseStore<BusiObject> createSalaryStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("bname");
		type.getField("bname").setType(String.class);
		type.addField("employno");
		type.getField("employno").setType(String.class);
		type.addField("upcode");
		type.getField("upcode").setType(String.class);
		type.addField("amount1");
		type.getField("amount1").setType(Double.class);
		type.addField("amount2");
		type.getField("amount2").setType(Double.class);
		type.addField("amount3");
		type.getField("amount3").setType(Double.class);
		type.addField("amount4");
		type.getField("amount4").setType(Double.class);
		type.addField("amount5");
		type.getField("amount5").setType(Double.class);
		type.addField("total");
		type.getField("total").setType(Double.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("null");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select a.bcode, a.bname, a.employno,upcode,amount1,amount2,amount3,amount4,amount5,(amount1%2Bamount2%2Bamount3%2Bamount4%2Bamount5)as total " +
				"from(select bcode,upcode,sum(isnull(amount1,0)) as amount1,sum(isnull(amount2,0)) as amount2," +
				"sum(isnull(amount3,0)) as amount3,sum(isnull(amount4,0)) as amount4,sum(isnull(amount5,0)) as amount5" +
				" from (select bcode, upcode,case when salarytype='1' then sum(amount) end as amount1, " +
				" case when salarytype='2' then sum(amount) end as amount2, case when salarytype='3' then sum(amount) end as amount3, " +
				"case when salarytype='4' then sum(amount) end as amount4,case when salarytype='5' then sum(amount) end as amount5 " +
				" from hr_salary where  upcode='{code}' group by bcode,upcode,salarytype )as a group by bcode,upcode)as b" +
				" inner join (select a.bcode,a.bname,b.employno from bcode a, bcode_job b where a.bcode = b.bcode) as a on a.bcode = b.bcode");

		info.setNeedAllRow("false");
		info.setForcenolimit("true");
		 info.setParent(store);// 关联主表
		 info.setLinkparentcolumns(new String[] { "code" }); // 关联主表字段
		 info.setLinkparent_chile_columns(new String[] { "upcode" });//
		// 关联主表字段
		Salarystore = new BaseStore<BusiObject>(type, info);
	
		return Salarystore;
	}

	BaseGrid Salarygrid = null;
	int row = 0;  //进行薪金修改的上一次的行数

	BaseGrid createSalaryGrid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		
		ColumnConfig C8 = new ColumnConfig("employno", "人员编号", 80);
		columns.add(C8);

		ColumnConfig C1 = new ColumnConfig("bname", "人员姓名", 60);
		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("amount1", "工资", 60);
		C2.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("amount2", "津贴", 60);
		C3.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("amount3", "社保", 60);
		C4.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C4);
		ColumnConfig C5 = new ColumnConfig("amount4", "个税", 60);
		C5.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("amount5", "花红", 60);
		C6.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("total", "合计", 70);
		C7.setNumberFormat(NumberFormat.getFormat("0.00"));
		columns.add(C7);

		ColumnModel cm = new ColumnModel(columns);
		Salarygrid = new BaseGrid(getSalaryStore(), cm,true,false)  {
			/**
			 * 换行前处理
			 */
			public void doBeforeRowChange() {
				save();
			}
		};
		cbs.setSelectionMode(SelectionMode.SINGLE);
		Salarygrid.setSelectionModel(cbs);
		Salarygrid.setHeight(430);
		Salarygrid.setWidth(565);
		return Salarygrid;
	}
	BaseStore<BusiObject> hr_salarystore = null;

	BaseStore<BusiObject> getStore() {
		if (hr_salarystore == null) {
			createhr_salaryStore();
		}
		return hr_salarystore;
	}

	BaseStore<BusiObject> createhr_salaryStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("bcode");
		type.getField("bcode").setType(String.class);
		type.addField("allowanceno_");
		type.getField("allowanceno_").setType(String.class);
		type.addField("amount");
		type.getField("amount").setType(Double.class);
		type.addField("status");
		type.getField("status").setType(Integer.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("salarydate");
		type.getField("salarydate").setType(Date.class);
		type.addField("upcode");
		type.getField("upcode").setType(String.class);
		type.addField("bname");
		type.getField("bname").setType(String.class);
		type.addField("desc_cn");
		type.getField("desc_cn").setType(String.class);
		type.addField("readOnly");
		type.getField("readOnly").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_salary");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from hr_salary where amount != 0 and bcode='{bcode}' and   upcode='{upcode}' ");
		info.setParent(getSalaryStore());// 关联主表
		info.setLinkparentcolumns(new String[] { "bcode","upcode" }); // 关联主表字段
		info.setLinkparent_chile_columns(new String[] { "bcode","upcode"  });// 关联主表字段
		hr_salarystore = new BaseStore<BusiObject>(type, info);
		hr_salarystore.addEditdisableItem(new Editdisable("readOnly", "1",
				BaseStore.EditDisableType.IN));
		return hr_salarystore;
	}
	
	BaseGrid salarydetailgrid = null;
	NumberField C_num4;

	BaseGrid createGrid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig C2 = new ColumnConfig("bcode", "人员", 60);
		BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>("a.bcode","a.bname","bcode a, bcode_job b"," where a.bcode = b.bcode and b.employstatus = '在职'",true);
		
		C2.setRenderer(bsb2);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("allowanceno_", "薪金类别", 80);
		BaseComboBoxForm<BaseModelData> bsb3 = new BaseComboBoxForm<BaseModelData>("code","desc_cn","hr_salary_item","",true);
		
		C3.setRenderer(bsb3);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("amount", "金额", 60);
		C4.setNumberFormat(NumberFormat.getFormat("0.00"));
		C_num4 = new  NumberField(); 
		C_num4.addListener(Events.Change, getListener());
		C4.setEditor(new CellEditor(C_num4));
		columns.add(C4);

		ColumnModel cm = new ColumnModel(columns);
		salarydetailgrid = new BaseGrid(createhr_salaryStore(), cm, false, false);
		cbs.setSelectionMode(SelectionMode.SINGLE);
		salarydetailgrid.setSelectionModel(cbs);
		salarydetailgrid.setHeight(430);
		salarydetailgrid.setWidth(240);
		
		return salarydetailgrid;
	}
	
	BaseGrid<BusiObject> createGrid1() {
		BaseGrid<BusiObject> grid = null;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig C2 = new ColumnConfig("m1", "上月发薪人数", 90);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("m2", "本月发薪人数", 90);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("m3", "上月离职人数", 90);
		columns.add(C4);	
		ColumnConfig C5 = new ColumnConfig("m4", "本月入职人数", 90);
		columns.add(C5);
		ColumnConfig C6 = new ColumnConfig("m5", "上月停发人数", 90);
		columns.add(C6);
		ColumnConfig C7 = new ColumnConfig("m6", "本月停发人数", 90);
		columns.add(C7);
		ColumnConfig C8 = new ColumnConfig("m7", "本月入职但晚于截止日期的人数", 180);
		columns.add(C8);
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid<BusiObject>(mstore, cm ,false,false);
		cbs.setSelectionMode(SelectionMode.SIMPLE);//控制是否可以多选每行后面的复选框
		grid.setSelectionModel(cbs);
		grid.setHeight(163);
		grid.setWidth(776);
		grid.setBorders(false);
		return grid;
	}	
	
	BaseGrid<BusiObject> createGrid2(BaseStore st) {
		BaseGrid<BusiObject> grid = null;
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig C2 = new ColumnConfig("bname", "姓名", 45);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("bcode", "员工编号", 65);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("depName", "部门", 65);
		columns.add(C4);		
		ColumnModel cm = new ColumnModel(columns);
		grid = new BaseGrid<BusiObject>(st, cm ,false,false);
		cbs.setSelectionMode(SelectionMode.SIMPLE);//控制是否可以多选每行后面的复选框
		grid.setSelectionModel(cbs);
		grid.setHeight(163);
		grid.setWidth(776);
		grid.setBorders(false);
		return grid;
	}	
	
	int sync = 0;
	Listener<BaseEvent> defaultlistener;

	Listener<BaseEvent> getListener() {
		if (defaultlistener != null) {
			return defaultlistener;
		}

		defaultlistener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				sync++;
				try {
					if (sync == 1) {
						if (be.getType() == Events.Select) {
							if (be.getSource().equals(ratify)) {
								
								store.setValue("status", "524288");
								store.trySave(store.getCurcowindex());
							}
							else if (be.getSource().equals(printer)) {
								String code = "";
								code = store.getValue("icode").toString();
								Window.open(GWT.getHostPageBaseURL() + "hr_Jsp/rptSalary.jsp?data="+code, "_blank","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
							}
							else if (be.getSource().equals(search)) {
								String searchStr = searchText.getRawValue();
								if (searchStr.equals("")) {
									MessageBox.alert("提示", "查询条件不能为空，请输入查询条件", null);
									return;
								}
								
								String oldSql = getSalaryStore().getStoreinfo().getSql();
								String newSql = oldSql;
								newSql = newSql.substring(0, newSql.indexOf("{code}")) + store.getValue("code") + newSql.substring(newSql.indexOf("{code}") + 6);
								newSql += " where employno like '%25" + searchStr + "%25' or bname like '%25" + searchStr + "%25'";
								getSalaryStore().getStoreinfo().setSql(newSql);
								getSalaryStore().reload();
								getSalaryStore().getStoreinfo().setSql(oldSql);
							}
							else if (be.getSource().equals(deleteAll)) {
								
								deleteAll();
							}else if (be.getSource().equals(delete)) {
								
								delete();
							}else if(be.getSource().equals(export)){
								String code = "";
								code = store.getValue("code").toString();
								Window.open(GWT.getHostPageBaseURL() + "hr_Jsp/exportBankSalary.jsp?upcode="+code, null, null);
								
							}else if (be.getSource().equals(seal)) {
								
								sealAction("1");
							}else if (be.getSource().equals(seal_cancel)) {
								
								sealAction("0");
							}
							
						} else if (be.getType() == Events.Change) {
							if (be.getSource().equals(C_num4)) {
							}
						} else if (be.getType() == Events.KeyUp) {
							if (be instanceof ComponentEvent) {
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{
								}
							}
						}
					}
				} finally {
					sync--;
				}
			}

		};
		return defaultlistener;
	}
	
	private void sealAction(String sealStatus) {
		List<String> lists = new ArrayList<String>();
		String sealSql = "update hr_salary set readOnly = '" + sealStatus + "' where allowanceno_ != 'A99' and upcode = '" + store.getValue("code") + "'"; 
		lists.add(sealSql);
		update(lists, "封存操作成功");
	}
	
	public boolean update(List<String> lists, final String tip) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		for (String sql : lists) {
			csql.getV().add(sql);
		}
		if (csql.getV().size() <= 0) {
			return false;
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
								Info.display("提示", tip);
								if (tip.equals("封存操作成功")) {
									String sql = getSalaryStore().getStoreinfo().getSql();
									int start = sql.indexOf("{");
									int end = sql.indexOf("}");
									String newSql = sql.substring(0, start) + store.getValue(sql.substring(start + 1, end)) + sql.substring(end + 1);
									getSalaryStore().getStoreinfo().setSql(newSql);
									getSalaryStore().reload();
									getSalaryStore().getStoreinfo().setSql(sql);
								}
							}
						}
			});
		}
		
		return true;
		
	}
	

	void delete(){
		final Object code = store.getValue("code");
		final String bcode = Salarystore.getValue("bcode").toString();
		MessageBox.confirm("提示	", "确定删除编号为" + bcode + "的" +
				"员工发薪代码为 "+code+"的发薪记录?", new Listener<MessageBoxEvent> (){

			@Override
			public void handleEvent(MessageBoxEvent be) {
	
			
				if(be.getButtonClicked().getText().equals(GXT.MESSAGES.messageBox_yes()))
						{
							if(code!=null) {
							//小陈修改，这个主要做级联删除相关的发薪金记录的数据  2011-03-08
							String delSalarySql = "delete hr_salary where upcode = '" +code+"' and bcode = '" + bcode + "'";
							
							CommandSyncContainer list = new CommandSyncContainer();
							CommandSyncsql csql = new CommandSyncsql();
							
							csql.getV().add(delSalarySql);
							csql.setContinueorrollback(false);
							list.add(csql);
							
							final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
							.create(com.base.myproject.client.tools.GreetingService.class);
					greetingService.SendCommandSync(list,
							new AsyncCallback<CommandSyncReturnObject>() {

								@Override
								public void onFailure(Throwable caught) {
									MessageBox.alert("错误", "网络连接失败", null);

								}

								@Override
								public void onSuccess(CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "成功");
										store.reload();
										
									} else {
										MessageBox.alert("错误", "" + result.getMessage(),
												null);
										
									
									}

								}

							});
							
							}
						}
				
			}
			
		});
	}
	
	void deleteAll(){
		Object code = store.getValue("code");
		MessageBox.confirm("提示	", "是否删除整个工资数据？即发薪代码为 "+code+" 所有人员的工资。", new Listener<MessageBoxEvent> (){

			@Override
			public void handleEvent(MessageBoxEvent be) {
	
			
				if(be.getButtonClicked().getText().equals(GXT.MESSAGES.messageBox_yes()))
						{
					Object code = store.getValue("code");
							if(code!=null)
							{
							//小陈修改，这个主要做级联删除相关的发薪金记录的数据  2011-03-08
							String delMainSql = "delete hr_salary_main_c where code = '" + code + "'";
							String delSalarySql = "delete hr_salary where upcode = '" +code+"'";
							String delRangeSql = "delete hr_range_bcode where sheetcode='MakeSalaryX' and upcode = '"+ code +"'";
							String delZySql = "delete hr_range_zy_c where sheetcode='MakeSalaryX' and upcode = '"+ code +"'";
							String delGroupSql = "delete hr_range_jobgroup where sheetcode='MakeSalaryX' and upcode = '"+ code +"'";
							String delPropertySql = "delete hr_range_jobproperty where sheetcode='MakeSalaryX' and upcode = '"+ code +"'";
							String delTypeSql = "delete hr_range_jobtype where sheetcode='MakeSalaryX' and upcode = '"+ code +"'";
							
							CommandSyncContainer list = new CommandSyncContainer();
							CommandSyncsql csql = new CommandSyncsql();
							
							csql.getV().add(delMainSql);
							csql.getV().add(delRangeSql);
							csql.getV().add(delSalarySql);
							csql.getV().add(delZySql);
							csql.getV().add(delGroupSql);
							csql.getV().add(delPropertySql);
							csql.getV().add(delTypeSql);
							csql.setContinueorrollback(false);
							list.add(csql);
							
							final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
							.create(com.base.myproject.client.tools.GreetingService.class);
					greetingService.SendCommandSync(list,
							new AsyncCallback<CommandSyncReturnObject>() {

								@Override
								public void onFailure(Throwable caught) {
									MessageBox.alert("错误", "网络连接失败", null);

								}

								@Override
								public void onSuccess(CommandSyncReturnObject result) {
									if (result.isB()) {
										Info.display("", "成功");
										store.reload();
										
									} else {
										MessageBox.alert("错误", "" + result.getMessage(),
												null);
										
									
									}

								}

							});
							
							}
						}
				
			}
			
		});
	}
	
	@Override
	public void BaseStoreEventHandle(BaseStoreEvent evt) {
		if(this.icode !=null)
		{
			GWT.log("bingo1");
		ModelData md = evt.getBasestore().findModel("code",this.icode);
		List<ModelData> selection  =new ArrayList<ModelData>();
		selection.add(md);
		Salarygrid .getSelectionModel().setSelection(selection);
		GWT.log("bingo2");
		}
	}
	void init_store(){
		BusiObject bo = new BusiObject();
		bo.set("m1", "110");
		bo.set("m2", "109");
		bo.set("m3", "1");
		bo.set("m4", "0");
		bo.set("m5", "0");
		bo.set("m6", "0");
		bo.set("m7", "0");
		mstore.add(bo,false,false);
		
		BusiObject bo2 = new BusiObject();
		bo2.set("bname", "莫伟文");
		bo2.set("bcode", "0027");
		bo2.set("depName", "保安部");
		mstore2.add(bo2,false,false);
		
		BusiObject bo3 = new BusiObject();
		bo3.set("bname", "陈明忠");
		bo3.set("bcode", "0029");
		bo3.set("depName", "电脑房");
		mstore3.add(bo3,false,false);
		
		BusiObject bo4 = new BusiObject();
		bo4.set("bname", "郭友彬");
		bo4.set("bcode", "0037");
		bo4.set("depName", "财务部");
		mstore4.add(bo4,false,false);
		
		BusiObject bo5 = new BusiObject();
		bo5.set("bname", "黄杰平");
		bo5.set("bcode", "0127");
		bo5.set("depName", "咖啡厅");
		mstore5.add(bo5,false,false);
		
		BusiObject bo6 = new BusiObject();
		bo6.set("bname", "何硕华");
		bo6.set("bcode", "0047");
		bo6.set("depName", "空调组");
		mstore6.add(bo6,false,false);
		
		BusiObject bo7 = new BusiObject();
		bo7.set("bname", "萧丽");
		bo7.set("bcode", "0067");
		bo7.set("depName", "华美轩");
		mstore7.add(bo7,false,false);
		
	}
	
}
